package cn.yuyin.item;

import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import cn.yuyin.main.Main;
import cn.yuyin.page.SuperPage;
/**
 * 
 * @author Administrator
 *
 */
public class TableItem extends Item{

	public SuperPage superPage;
	public Image image = null;
	public TableItem(int index,int x, int y, String text) {
		super(x, y, text);
		this.index = index;
		Font font=Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE);
		width = font.stringWidth(text)+2*Main.margin;
		height = font.getHeight()+2*Main.rowspace;	
		
		endX = x+width;
		endY = y+height;
	}
	
	public TableItem(int index,int x, int y, Image image) {
		super(x, y, "");
		this.index = index;
		this.image = image;
		width = image.getWidth()+2*Main.margin;
		height = image.getHeight()+2*Main.rowspace;	
		
		endX = x+width;
		endY = y+height;
	}

	public void paint(Graphics g) {
		if(index == Main.superPage.index){
			ishaveFouse = true;
		}else {
			ishaveFouse = false;
		}
		int color = g.getColor();
		if(ishaveFouse){
			if(superPage!=null){
				superPage.paint(g);
			}
			g.setColor(0xF2F5F8);
			g.fillRect(0, 0, Main.WIDTH, y+height);
			g.setColor(0xC0C0C0);
			g.fillRect(x, y, width, height);
			g.setColor(0);
			g.drawRect(x, y, width, height);			
			g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE));
			if(image!=null){
				g.drawImage(image, x+Main.margin, y+Main.rowspace, 0);
			}else{
				g.drawString(text, x+Main.margin, y+Main.rowspace, 0);
			}			
			g.setFont(Main.font);
			g.drawLine(0, y+height, Main.WIDTH, y+height);
			
		}else{
			g.setColor(0);
			g.drawRect(x, y, width, height);
			if(image!=null){
				g.drawImage(image, x+Main.margin, y+Main.rowspace, 0);
			}else{
				g.drawString(text, x+Main.margin, y+Main.rowspace, 0);
			}			
			g.drawLine(0, 0, Main.WIDTH, y+height);
		}
		g.setColor(color);
	}

	public void keyReleased(int keyCode) {
		if(superPage!=null){
			superPage.keyReleased(keyCode);
		}
	}

	public void pointerPressed(int x, int y) {
		
	}

	public void pointerReleased(int x, int y) {
		
	}

}
